package com.alpha.feign.common.entity;

import com.alpha.core.entity.AlphaEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 字典
 *
 * @author chenruwan
 * @since 2022-01-01
 */
@Data
@Schema(name = "字典")
@Accessors(chain = true)
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Dictionary extends AlphaEntity {
    @NotNull(message = "字典名称不能为空")
    @Schema(description = "字典名称")
    private String name;

    @NotNull(message = "字典编码不能为空")
    @Schema(description = "字典编码")
    private String code;

    @NotNull(message = "字典取值不能为空")
    @Schema(description = "字典取值")
    private String value;

    @NotNull(message = "字典类型不能为空")
    @Schema(description = "字典类型", defaultValue = "0")
    private Long parentId;

    @TableField(exist = false)
    @Schema(description = "字典类型", accessMode = Schema.AccessMode.READ_ONLY)
    private Dictionary parent;

    @TableField(exist = false)
    @Schema(description = "children", accessMode = Schema.AccessMode.READ_ONLY)
    private List<Dictionary> children;

    @SuppressWarnings("unused")
    public Dictionary(String name, String code, String value, Long parentId) {
        // NotNull fields
        this.name = name;
        this.code = code;
        this.value = value;
        this.parentId = parentId;
    }
}
